//
//  HQYHomeCellDetailViewController.m
//  Go!
//
//  Created by rimi on 16/7/11.
//  Copyright © 2016年 黄秋燕. All rights reserved.
//

/**< 开眼效果的详细页面 */
#import "HQYHomeCellDetailViewController.h"
#import "HQYSearchViewController.h" // 搜索页面
#import "GoodsArray.h" // 购物车存储信息

@interface HQYHomeCellDetailViewController ()<UIWebViewDelegate>

@end

@implementation HQYHomeCellDetailViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.backItem = [[UIBarButtonItem alloc] initWithImage:IMAGE(@"") style:UIBarButtonItemStylePlain target:self action:@selector(clickBackItem)];
    self.navigationItem.leftBarButtonItem = self.backItem;
    
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = YES;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self initializeUserInterface];
}


#pragma mark - initialize
/**< 初始化用户界面 */
- (void)initializeUserInterface {
    self.view.backgroundColor = [UIColor whiteColor];
    // 网页内容
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 20, ScreenW, ScreenH - 20)];
    // 关闭弹簧效果
    webView.scrollView.bounces = NO;
    // 配置请求
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
    // 加载数据
    [webView loadRequest:request];
    // 添加视图
    [self.view addSubview:webView];
    
    
    // 返回按钮
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(12, 16, 30, 30);
    backBtn.layer.cornerRadius = 15;
    [backBtn addTarget:self action:@selector(clickedBackBtn) forControlEvents:UIControlEventTouchUpInside];
//    backBtn.backgroundColor = [UIColor redColor];
    [webView.scrollView addSubview:backBtn];
    
    // 搜索按钮
    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    searchBtn.frame = CGRectMake(ScreenW - 82, 17, 30, 30);
    searchBtn.layer.cornerRadius = 15;
    [searchBtn addTarget:self action:@selector(clickedSearchBtn) forControlEvents:UIControlEventTouchUpInside];
//    searchBtn.backgroundColor = [UIColor redColor];
    [webView.scrollView addSubview:searchBtn];
    
    // 主页按钮
    UIButton *homeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    homeBtn.frame = CGRectMake(ScreenW - 40, 17, 30, 30);
    homeBtn.layer.cornerRadius = 15;
    [homeBtn addTarget:self action:@selector(clickedHomeBtn) forControlEvents:UIControlEventTouchUpInside];
//    homeBtn.backgroundColor = [UIColor redColor];
    [webView.scrollView addSubview:homeBtn];
    
    // 收藏按钮
    UIButton *collectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    collectBtn.frame = CGRectMake(ScreenW - 40, 161, 32, 32);
    collectBtn.layer.cornerRadius = 16;
//    collectBtn.backgroundColor = ColorWith(144, 144, 144);
    [webView.scrollView addSubview:collectBtn];
    
    // 购买按钮
    UIButton *buyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    buyBtn.frame = CGRectMake(0, ScreenH - 56 - 20, ScreenW, 56);
    [buyBtn addTarget:self action:@selector(clickedBuyBtn) forControlEvents:UIControlEventTouchUpInside];
//    buyBtn.backgroundColor = [UIColor redColor];
    [webView addSubview:buyBtn];
}

#pragma mark - 按钮监听
#pragma mark --返回按钮
- (void)clickedBackBtn {
    [self clickBackItem];
}

#pragma mark --搜索按钮
- (void)clickedSearchBtn {
    HQYSearchViewController *searchVC = [[HQYSearchViewController alloc] init];
    [self.navigationController pushViewController:searchVC animated:YES];
}

#pragma mark --主页按钮
- (void)clickedHomeBtn {
    self.tabBarController.selectedIndex = 2;
    [self.navigationController popToRootViewControllerAnimated:NO];
}

#pragma mark --购买按钮
- (void)clickedBuyBtn {
    [[GoodsArray shareArray] buysomethingWithAboutGoodsImage:_dict[@"icon"] GoodsName:_dict[@"name"] Price:_dict[@"price"]];
    [Tools showAlertWithMessage:@"商品在购物车等亲哦~"];
    
}


@end
